<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <jsp:include page="../incHead.jsp">
        <jsp:param name="title" value="forestVisit.title" />
    </jsp:include>
    <body>        
        <jsp:include page="../incHeader.jsp"/>
        <div id="container">
            <jsp:include page="../incMenu.jsp"/>
            <div id="content">
                <div class="divOfForms">
                    <div id="title_subsection">
                        <h3><fmt:message key="forestVisit.addForestVisit"/></h3>
                    </div>
                    <form:form action="addForestVisit" method="GET">
                        <table class="tableOfForms">
                            <tr>
                                <td class="outputInTable"><form:label path="pickerDTO"><fmt:message key="forestVisit.picker"/></form:label></td>
                                    <td>
                                    <form:select path="pickerDTO">
                                        <form:option value="" label="--Please Select"/>
                                        <form:options items="${pickers}" />
                                    </form:select>
                                </td>
                                <td><form:errors class="error" path="pickerDTO" cssClass="error"/></td>
                            </tr>
                            <tr>
                                <td class="outputInTable"><form:label path="forestDTO"><fmt:message key="forestVisit.forest"/></form:label></td>
                                    <td>
                                    <form:select path="forestDTO">
                                        <form:option value="" label="--Please Select"/>
                                        <form:options items="${forests}" />
                                    </form:select>
                                </td>
                                <td><form:errors class="error" path="forestDTO" cssClass="error"/></td>
                            </tr>
                            <tr>
                                <td class="outputInTable"><form:label path="dateOfVisit"><fmt:message key="forestVisit.date"/></form:label></td>
                                <td><form:input path="dateOfVisit" /></td>
                                <td><form:errors class="error" path="dateOfVisit" cssClass="error"/></td>
                            </tr>
                            <tr>
                                <td class="outputInTable"><form:label path="description"><fmt:message key="forestVisit.description"/></form:label></td>
                                <td><form:input path="description" /></td>
                                <td><form:errors class="error" path="description" cssClass="error"/></td>
                            </tr>
                            <tr>
                                <td class="outputInTable"><form:label path="mushroomsFound">Mushrooms found</form:label></td>
                                    <td>
                                    <form:select path="mushroomsFound" multiple="multiple" size="5">
                                        <!--form:option value="" label="--Please Select"/-->
                                        <form:options items="${mushrooms}" />
                                    </form:select>
                                </td>
                                <td><form:errors class="error" path="mushroomsFound" cssClass="error"/></td>
                            </tr>
                            <tr>
                                <td></td>
                                <td><input type="submit" value=<fmt:message key="general.submit"/> /></td>
                                <td></td>
                            </tr>
                        </table>
                    </form:form>
                </div>
                <p class="error">${error}</p>
                <br/>
                <div class="divOfItems">    
                    <div id="title_subsection">
                        <h3><fmt:message key="forestVisit.all"/></h3>
                    </div>
                    <table class="allTable">
                        <th><fmt:message key="forestVisit.picker"/></th>
                        <th><fmt:message key="forestVisit.forest"/></th>
                        <th><fmt:message key="forestVisit.date"/></th>
                        <th><fmt:message key="forestVisit.description"/></th>
                        <sec:authorize access="hasRole('ROLE_ADMIN')">
                            <th colspan="2"><fmt:message key="general.action"/></th>
                        </sec:authorize>
                        <th><fmt:message key="forestVisit.mushrooms"/></th>
                        <c:forEach var="visit" items="${visits}" >
                            <tr>
                                <td><c:out value="${visit.pickerDTO}" /></td>
                                <td><c:out value="${visit.forestDTO}" /></td>
                                <td><c:out value="${visit.dateOfVisit}" /></td>
                                <td><c:out value="${visit.description}" /></td>
                            <sec:authorize access="hasRole('ROLE_ADMIN')">
                                <td><a href="editForestVisit?id=${visit.id}"><fmt:message key="general.edit"/></a></td>
                                <td><a href="removeForestVisit?id=${visit.id}" 
                                       onclick="return confirm('Are you sure you want to delete selected forest visit?')">
                                        <fmt:message key="general.remove"/></a></td>
                            </sec:authorize>
                            <td><a href="showMushrooms?id=${visit.id}"><fmt:message key="forestVisit.showMushrooms"/></a></td>
                            </tr>
                        </c:forEach>
                    </table>   
                    <fmt:message key="sortoptions"/><br />
                    <form action="visitSort" >
                        <fmt:message key="mushroom.name"/>:&nbsp;<input type="text" name="name" />
                        <select name="sortBy">
                            <option value="byPicker"><fmt:message key="bypicker"/></option>
                            <option value="byForest"><fmt:message key="byforest"/></option>
                            <option value="default"><fmt:message key="default"/></option>
                        </select>
                        <input type="submit" value="Submit" />
                    </form>
                </div>
            </div>
        </div>
    </body>
</html>
